<template>
  <div  class="app-container calendar-list-container">
    <div v-if="visible">
    <el-form :model="entity" :rules="dataRule" ref="entity"  label-width="100px">
      <el-row>
         <el-col :span="22">
          <el-form-item label="仓库名称" prop="warehouseName">
            <el-input v-model="entity.warehouseName" :disabled="view"></el-input>
          </el-form-item>  
        </el-col>
     </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <div class="dialog-footer-div">
          <el-button @click="cancel()">取消</el-button>
          <el-button v-if="!view" type="primary" @click="submit()">确定</el-button>
      </div>
    </span>
  </div>
  </div>
</template>

<script>
import request from '@/router/axios'
import { Message, MessageBox } from 'element-ui'
import url from '@/const/apiURL'  
import { dict } from '@/const/dict'

export default {
  data() {
    return {
       view: false,
       url:'',
       entity: { },
       dataRule: {
         warehouseName: [
            { required: true, message: '仓库名称不能为空', trigger: 'blur' },
            { min: 2, message: '长度在不能小于2', trigger: 'blur' }
          ]
       }
    }
  },
  created() {
  },
  props: {
     visible: {
      type: Boolean,
      default: function() {
        return false
      }
    }
  },
  methods: {
    init(title,entity,view,url){
      this.$nextTick(() => {
        this.title = title
        this.$refs['entity'].resetFields()
        this.view = view
        this.entity = entity
        this.url= url
      })
    },
    cancel(){
      this.$emit('cancel')
    },
    submit(){
     this.$refs['entity'].validate((valid) => {
          if (valid) {
            this.handleUrl(this.entity).then((data)=> {
              if(data){
                  this.$emit('cancel')
              }
            })
          }
       })
    },
    handleUrl(data) {
      return request({
        url: this.url,
        method: 'post',
        data
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>

</style>
